<?php
/*
 * planning/edit.phtml
 */
?>
<?php

use RHX\Model\Object\PlanningSemaine;
use RHX\Helper\RHDateTime;
use RHX\Model\Object\Site;
use RHX\Model\Object\XRules;
?>
<?php
$employes	 = $this->employes;
$plannings	 = $this->plannings;
$codes		 = $this->codes;
$codec		 = $this->codec;
$days		 = $this->daysOfWeek;
$editable	 = $this->editable;
$siteId		 = $this->site;
$siteObj	 = $this->siteObj;
$post		 = $this->post;

// Objet Vide
$emptyPlanning		 = new PlanningSemaine($this->adapter);
$emptyPlanning->id	 = 100000000;
$tpl			 = $this->template;
$calculator		 = null;

$dayName = array(
    'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche',
);

// Temps
$lundi		 = new RHDateTime($this->lundi);
$mardi		 = new RHDateTime($this->lundi);
$mardi->modify('next day');
$mercredi	 = new RHDateTime($this->lundi);
$mercredi->modify('next wednesday');
$jeudi		 = new RHDateTime($this->lundi);
$jeudi->modify('next thursday');
$vendredi	 = new RHDateTime($this->lundi);
$vendredi->modify('next friday');
$samedi		 = new RHDateTime($this->lundi);
$samedi->modify('next saturday');
$dimanche	 = new RHDateTime($this->lundi);
$dimanche->modify('next sunday');

// EDITABLE OU PAS Par rapport à la date
$now		 = new \DateTime('now');
$dateLundi	 = new \DateTime($this->lundi);
$dateDimanche	 = new \DateTime($this->lundi);
$dateDimanche->modify('next sunday');
if ((($now > $dateLundi) && ($now < $dateDimanche)) || ($now == $dateLundi) || ($now == $dateDimanche)) {
    $editable = true;
}

// Variables de Synthèse
//
// Heures Travaillés
$lundiHeureTravaille	 = new RHDateTime();
$lundiHeureTravaille->setTime();
$mardiHeureTravaille	 = new RHDateTime();
$mardiHeureTravaille->setTime();
$mercrediHeureTravaille	 = new RHDateTime();
$mercrediHeureTravaille->setTime();
$jeudiHeureTravaille	 = new RHDateTime();
$jeudiHeureTravaille->setTime();
$vendrediHeureTravaille	 = new RHDateTime();
$vendrediHeureTravaille->setTime();
$samediHeureTravaille	 = new RHDateTime();
$samediHeureTravaille->setTime();
$dimancheHeureTravaille	 = new RHDateTime();
$dimancheHeureTravaille->setTime();

// Main D'oeuvre sur site
$coef		 = 1.54;
$lundiMO	 = 0;
$mardiMO	 = 0;
$mercrediMO	 = 0;
$jeudiMO	 = 0;
$vendrediMO	 = 0;
$samediMO	 = 0;
$dimancheMO	 = 0;

// Présence à 12:00
$refPresent	 = new RHDateTime();
$refPresent->setTime('12:00');
$lundiPresent	 = 0;
$mardiPresent	 = 0;
$mercrediPresent = 0;
$jeudiPresent	 = 0;
$vendrediPresent = 0;
$samediPresent	 = 0;
$dimanchePresent = 0;

// Variables pour le JS
$planningID = array();
?>
<div class="content-body">
    <div class="rhx-goback">
	<?php if ((int) $post->dialog != 1): ?>
    	<button class="btn btn-inverse" onclick="normalScreenLayout();">Retour à la liste des Semaines</button>
	<?php endif; ?>
    </div>
    <?php if ((int) $post->dialog != 1): ?>
        <div class='rhx-siteTitle btn'  onclick='$("#" + ID).click();
    	    return false;'><?php echo $siteObj->libelle; ?></div>
	 <?php endif; ?>
    <div class="rhx-planning-title">
	<a href="#" id="selectorSemaine" data-type="select" style="color: #fff;" onclick="return false;">
	    <em>Semaine <b><?php echo $lundi->dateFr(); ?></b> au <b><?php echo $dimanche->dateFr(); ?></b></em>
	</a>
    </div>
    <div id="planning-tabs">
	<ul>
	    <li>
		<a href="#planning-semaine">Planning Semaine</a>
	    </li>
	    <li>
		<a href="#planning-type">Planning Type</a>
	    </li>
	</ul>
	<div id="planning-semaine" class='small-font'>
	    <table class="pl-table table-condensed" style="font-size: 0.9em;">
		<thead>
		    <tr>
			<td rowspan='2'>Mat.</td>
			<td rowspan='2'>Poste</td>
			<td rowspan='2'>Prénom</td>
			<td rowspan="2">Contrat Horaire</td>
			<?php if ($days['lundi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $lundi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['mardi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $mardi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['mercredi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $mercredi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['jeudi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $jeudi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['vendredi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $vendredi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['samedi']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $samedi->dateFr(); ?></b></td><?php endif; ?>
			<?php if ($days['dimanche']): ?><td colspan='6' style="border-left-width: 2px;border-right-width: 2px;"><b><?php echo $dimanche->dateFr(); ?></b></td><?php endif; ?>
			<td rowspan="2">Heures modulées</td>
			<td rowspan="2">Ret., Abs. et Dép. Ant.</td>
			<td rowspan="2">Heures non planifiées</td>
		    </tr>
		    <tr>
			<!-- lundi -->
			<?php if ($days['lundi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- mardi -->
			<?php if ($days['mardi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- mercredi -->
			<?php if ($days['mercredi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- jeudi -->
			<?php if ($days['jeudi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- vendredi -->
			<?php if ($days['vendredi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- samedi -->
			<?php if ($days['samedi']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>

			<!-- dimanche -->
			<?php if ($days['dimanche']): ?>
    			<td style="border-left-width: 2px;">Code</td>
    			<td>Entrée</td>
    			<td>Sortie</td>
    			<td>P</td>
    			<td>R</td>
    			<td style="border-right-width: 2px;">Transfert</td>
			<?php endif; ?>
		    </tr>
		</thead>
		<tbody>
		    <?php $jaune = 1; ?>
		    <?php foreach ($employes as $e): ?>
			<?php $calculator		 = new \RHX\Model\Object\XCalculator($e->getAdapter()); ?>
			<?php
			$heureTravaille		 = new RHDateTime();
			$heureTravaille->setTime();
			$heureNonPlannifie	 = new RHDateTime();
			// Avenant pour récupérer l'heure hebdomadaire
			$avenant		 = $e->getAvenant($lundi->date());
			//var_dump($avenant);
			$heureHebdo		 = floatval($avenant->hebdo);
			$taux			 = floatval($avenant->taux);
			$poste			 = $e->getPoste();
			$pl			 = (isset($plannings[$e->matricule]) ? $plannings[$e->matricule] : $emptyPlanning);
			$planningID[]		 = $pl;
			//var_dump($template);
			//
			$emptyPlanning->id++;
			// Couleur Jaune
			$colorJaune		 = ($jaune % 2) ? 'jaune1' : 'jaune2';
			$jaune++;
			?>
    		    <tr style="text-align: center;">
    			<td class="<?php echo $colorJaune; ?>">
    			    <a href="#" class="show-resume" data-id="<?php echo ($pl->id >= 100000000) ? 0 : $pl->id; ?>" data-matricule="<?php echo $e->matricule; ?>" data-lundi="<?php echo $lundi->date(); ?>"><?php echo $e->matricule; ?></a>
    			</td>
    			<td class="<?php echo $colorJaune; ?>"><?php echo $poste->code; ?></td>
    			<td class="<?php echo $colorJaune; ?>">
    			    <a href='<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'edit', 'id' => $e->matricule)) ?>' target="_blank"><?php echo $e->prenom; ?></a>
    			</td>
    			<td class="<?php echo $colorJaune; ?>"><?php echo $e->getHoraireHebdo(true, $lundi->date()); ?></td>

    			<!-- lundi -->
			    <?php if ($days['lundi']): ?>
				<?php
				$color		 = $codec[$pl->lundi_code];
				$lundiEntree	 = new RHDateTime($pl->lundi_entree);
				$lundiSortie	 = new RHDateTime($pl->lundi_sortie);

				$classEditLink = (int) in_array($pl->lundi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->lundi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->lundi_entree, $pl->lundi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$lundiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$lundiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($lundiEntree, $lundiSortie)) {
					    $lundiPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->lundi_code, $pl->lundi_entree, $pl->lundi_sortie, $template->lundi_entree, $template->lundi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->lundi_entree, $pl->lundi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$lundiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$lundiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($lundiEntree, $lundiSortie)) {
					    $lundiPresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-lundi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="lundi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->lundi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->lundi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-lundi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="lundi" data-id="<?php echo $pl->id; ?>">
					<?php echo $lundiEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->lundi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-lundi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="lundi" data-id="<?php echo $pl->id; ?>">
					<?php echo $lundiSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->lundi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-lundi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="lundi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->lundi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-lundi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="lundi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->lundi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- mardi -->
			    <?php if ($days['mardi']): ?>
				<?php
				$color		 = $codec[$pl->mardi_code];
				$mardiEntree	 = new RHDateTime($pl->mardi_entree);
				$mardiSortie	 = new RHDateTime($pl->mardi_sortie);
				$classEditLink	 = (int) in_array($pl->mardi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->mardi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->mardi_entree, $pl->mardi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$mardiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$mardiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($mardiEntree, $mardiSortie)) {
					    $mardiPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->mardi_code, $pl->mardi_entree, $pl->mardi_sortie, $template->mardi_entree, $template->mardi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->mardi_entree, $pl->mardi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$mardiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$mardiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($mardiEntree, $mardiSortie)) {
					    $mardiPresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-mardi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mardi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->mardi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->mardi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-mardi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mardi" data-id="<?php echo $pl->id; ?>">
					<?php echo $mardiEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->mardi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-mardi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mardi" data-id="<?php echo $pl->id; ?>">
					<?php echo $mardiSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->mardi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-mardi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mardi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->mardi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-mardi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mardi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->mardi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- mercredi -->
			    <?php if ($days['mercredi']): ?>
				<?php
				$color		 = $codec[$pl->mercredi_code];
				$mercrediEntree	 = new RHDateTime($pl->mercredi_entree);
				$mercrediSortie	 = new RHDateTime($pl->mercredi_sortie);
				$classEditLink	 = (int) in_array($pl->mercredi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->mercredi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->mercredi_entree, $pl->mercredi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$mercrediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$mercrediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($mercrediEntree, $mercrediSortie)) {
					    $mercrediPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->mercredi_code, $pl->mercredi_entree, $pl->mercredi_sortie, $template->mercredi_entree, $template->mercredi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->mercredi_entree, $pl->mercredi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$mercrediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$mercrediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($mercrediEntree, $mercrediSortie)) {
					    $mercrediPresent++;
					}
					break;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-mercredi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mercredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->mercredi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->mercredi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-mercredi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mercredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $mercrediEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->mercredi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-mercredi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mercredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $mercrediSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->mercredi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-mercredi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mercredi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->mercredi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-mercredi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="mercredi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->mercredi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- jeudi -->
			    <?php if ($days['jeudi']): ?>
				<?php
				$color		 = $codec[$pl->jeudi_code];
				$jeudiEntree	 = new RHDateTime($pl->jeudi_entree);
				$jeudiSortie	 = new RHDateTime($pl->jeudi_sortie);

				$classEditLink = (int) in_array($pl->jeudi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->jeudi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->jeudi_entree, $pl->jeudi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$jeudiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$jeudiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($jeudiEntree, $jeudiSortie)) {
					    $jeudiPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					//var_dump($template);
					$state		 = XRules::calculateLateState($pl->jeudi_code, $pl->jeudi_entree, $pl->jeudi_sortie, $template->jeudi_entree, $template->jeudi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->jeudi_entree, $pl->jeudi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$jeudiHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$jeudiMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($jeudiEntree, $jeudiSortie)) {
					    $jeudiPresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-jeudi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="jeudi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->jeudi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->jeudi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-jeudi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="jeudi" data-id="<?php echo $pl->id; ?>">
					<?php echo $jeudiEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->jeudi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-jeudi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="jeudi" data-id="<?php echo $pl->id; ?>">
					<?php echo $jeudiSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->jeudi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-jeudi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="jeudi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->jeudi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-jeudi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="jeudi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->jeudi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- vendredi -->
			    <?php if ($days['vendredi']): ?>
				<?php
				$color		 = $codec[$pl->vendredi_code];
				$vendrediEntree	 = new RHDateTime($pl->vendredi_entree);
				$vendrediSortie	 = new RHDateTime($pl->vendredi_sortie);
				$classEditLink	 = (int) in_array($pl->vendredi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->vendredi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->vendredi_entree, $pl->vendredi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$vendrediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$vendrediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($vendrediEntree, $vendrediSortie)) {
					    $vendrediPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->vendredi_code, $pl->vendredi_entree, $pl->vendredi_sortie, $template->vendredi_entree, $template->vendredi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->vendredi_entree, $pl->vendredi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$vendrediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$vendrediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($vendrediEntree, $vendrediSortie)) {
					    $vendrediPresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-vendredi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="vendredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->vendredi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->vendredi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-vendredi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="vendredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $vendrediEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->vendredi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-vendredi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="vendredi" data-id="<?php echo $pl->id; ?>">
					<?php echo $vendrediSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->vendredi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-vendredi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="vendredi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->vendredi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-vendredi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="vendredi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->vendredi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- samedi -->
			    <?php if ($days['samedi']): ?>
				<?php
				$color		 = $codec[$pl->samedi_code];
				$samediEntree	 = new RHDateTime($pl->samedi_entree);
				$samediSortie	 = new RHDateTime($pl->samedi_sortie);
				$classEditLink	 = (int) in_array($pl->samedi_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->samedi_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->samedi_entree, $pl->samedi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$samediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$samediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($samediEntree, $samediSortie)) {
					    $samediPresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->samedi_code, $pl->samedi_entree, $pl->samedi_sortie, $template->samedi_entree, $template->samedi_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->samedi_entree, $pl->samedi_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$samediHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$samediMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($samediEntree, $samediSortie)) {
					    $samediPresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-samedi-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="samedi" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->samedi_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->samedi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-samedi-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="samedi" data-id="<?php echo $pl->id; ?>">
					<?php echo $samediEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->samedi_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-samedi-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="samedi" data-id="<?php echo $pl->id; ?>">
					<?php echo $samediSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->samedi_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-samedi-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="samedi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->samedi_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-samedi-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="samedi" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->samedi_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<!-- dimanche -->
			    <?php if ($days['dimanche']): ?>
				<?php
				$color		 = $codec[$pl->dimanche_code];
				$dimancheEntree	 = new RHDateTime($pl->dimanche_entree);
				$dimancheSortie	 = new RHDateTime($pl->dimanche_sortie);
				$classEditLink	 = (int) in_array($pl->dimanche_code, array(XRules::EntreeSortie, XRules::TransfertEntrant, XRules::TransfertSortant)) ? 'no-edit-link' : 'edit-link';
				switch ((int) $pl->dimanche_code) {
				    case XRules::Present:
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->dimanche_entree, $pl->dimanche_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$dimancheHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$dimancheMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($dimancheEntree, $dimancheSortie)) {
					    $dimanchePresent++;
					}
					break;
				    case XRules::ProblemeRetardDepartAnticipe:
					// Template pour lequel le planning a été appliqué
					$template	 = $pl->getTemplate();
					// Etat de retard
					$state		 = XRules::calculateLateState($pl->dimanche_code, $pl->dimanche_entree, $pl->dimanche_sortie, $template->dimanche_entree, $template->dimanche_sortie);
					$value		 = $state['value'];
					$retard		 = $state['retard'];
					$departAnticipe	 = $state['departAnticipe'];
					$codeEntree	 = 'PRDA';
					$codeSortie	 = 'PRDA';
					if ($retard['etat']) {
					    // Retard
					    $codeEntree = 'RT';
					}
					if ($departAnticipe['etat']) {
					    // Départ Anticipé
					    $codeSortie = 'DA';
					}
					// Différence entree les heures
					$diff = RHDateTime::diffHours($pl->dimanche_entree, $pl->dimanche_sortie);
					$heureTravaille->addHours($diff, false);
					// Heures Travaillé sur Site Lundi
					$dimancheHeureTravaille->addHours($diff, false);
					// Main D'oeuvre
					$dimancheMO += RHDateTime::toFloat($diff) * $taux * $coef;
					// Présent
					if ($refPresent->isBetween($dimancheEntree, $dimancheSortie)) {
					    $dimanchePresent++;
					}
					break;
				}
				?>

				<td id="pl-<?php echo $pl->id; ?>-dimanche-code" class="<?php echo $color; ?>" style='border-left-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="dimanche" data-id="<?php echo $pl->id; ?>">
					<?php echo $codec[$pl->dimanche_code]; ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->dimanche_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeEntree;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-dimanche-entree" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="dimanche" data-id="<?php echo $pl->id; ?>">
					<?php echo $dimancheEntree->hours(); ?>
				    </a>
				</td>
				<?php
				if ((int) $pl->dimanche_code == XRules::ProblemeRetardDepartAnticipe) {
				    $color = $codeSortie;
				}
				?>
				<td id="pl-<?php echo $pl->id; ?>-dimanche-sortie" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="dimanche" data-id="<?php echo $pl->id; ?>">
					<?php echo $dimancheSortie->hours(); ?>
				    </a>
				</td>
				<?php $color = $codec[$pl->dimanche_code]; ?>
				<td id="pl-<?php echo $pl->id; ?>-dimanche-pause" class="<?php echo $color; ?>">
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="dimanche" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->dimanche_pause == 1) ? 'X' : ''; ?>
				    </a>
				</td>
				<td id="pl-<?php echo $pl->id; ?>-dimanche-repas" class="<?php echo $color; ?>"  style='border-right-width: 2px;'>
				    <a href='#' class="<?php echo $classEditLink; ?>" data-prefix="dimanche" data-id="<?php echo $pl->id; ?>">
					<?php echo ((int) $pl->dimanche_repas == 1) ? '1' : ''; ?>
				    </a>
				</td>
				<td class="stripes"></td>
			    <?php endif; ?>

    			<td>
    			    <span id="pl-<?php echo $pl->id; ?>-modulee">
				    <?php
				    //echo RHDateTime::hourNoSecond($pl->heure_prevues);
				    echo \RHX\Helper\Number::frenchFormat(RHDateTime::toFloat($calculator->getHeuresModulees($pl)->totalHours()));
				    ?>
    			    </span>
    			</td>
    			<td style="background: #ebfbff">
    			    <!-- RETARDS -->
    			    <span id="pl-<?php echo $pl->id; ?>-retard"><?php //echo RHDateTime::hourNoSecond($pl->retard_heure) . '(' . $pl->retard . ')';                  ?></span>
    			</td>
    			<td>
				<?php
				$class	 = '';
				$hp	 = floatval($pl->heure_non_planifie);
				if ($hp < 0) {
				    $class = 'minusValue';
				}
				elseif ($hp > 0) {
				    $class = 'plusValue';
				}
				?>
    			    <span id="pl-<?php echo $pl->id; ?>-planifie" class="<?php echo $class; ?>">
    				<!-- -->
    			    </span>
    			</td>
    		    </tr>
		    <?php endforeach; ?>
		    <?php
		    $dayCount = 0;
		    foreach ($days as $d) {
			if ($d)
			    $dayCount++;
		    }
		    $colCount	 = 4 + ($dayCount * 6) + 3;
		    ?>
		    <tr>
			<td colspan='<?php echo $colCount; ?>' class='jaune3'>Transfert Entrants <a href="#transfert" class="makeTransfert" data-site="<?php echo $siteId; ?>"><img title="Effectuer un Transfert Entrant" src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/transfer-32x32.png" ></a></td>
		    </tr>
		    <?php
		    $entrants	 = $this->entrants;
		    $count		 = count($entrants);
		    $jaune		 = 1;
		    ?>
		    <?php if ($count > 0): ?>
			<?php foreach ($entrants as $e): ?>
			    <?php
			    $en	 = null;
			    $i	 = 1;
			    foreach ($e as $value) {
				$en = $value;
//	    echo "<pre>Entrants$i</pre>";
//	    $i++;
//	    var_dump($en);
				break;
			    }
			    ?>
			    <?php
//			    echo '<pre>Avant affichage</pre>';
//			    var_dump($en);
			    $empl		 = $en->getEmploye();
			    $poste		 = $empl->getPoste();
			    ?>
			    <tr>
				<?php
				$matricule	 = '&nbsp;';
				$posteCode	 = '&nbsp;';
				$prenom		 = '&nbsp;';
				$contrat	 = '&nbsp;';
				?>
				<?php
				if ($en->arrivee == $siteId) {
				    $matricule	 = $empl->matricule;
				    $posteCode	 = $poste->code;
				    $prenom		 = $empl->prenom;
				    $contrat	 = $empl->getHoraireHebdo(true);
				}
				else {
				    continue;
				}
				?>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>">
				    <a href="<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'edit', 'id' => $matricule)) ?>" target="_blank"><?php echo $matricule; ?></a>
				</td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>"><?php echo $posteCode; ?></td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>">
				    <a href="<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'edit', 'id' => $matricule)) ?>" target="_blank"><?php echo $prenom; ?></a>
				</td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>"><?php echo $contrat; ?></td>

				<!-- lundi -->
				<?php if ($days['lundi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$lundi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$lundi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$lundi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$lundi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$lundi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$lundi->date()]->getSiteDepart();
					$id		 = $e[$lundi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- mardi -->
				<?php if ($days['mardi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$mardi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$mardi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$mardi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$mardi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$mardi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$mardi->date()]->getSiteDepart();
					$id		 = $e[$mardi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>

				<?php endif; ?>

				<!-- mercredi -->
				<?php if ($days['mercredi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$mercredi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$mercredi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$mercredi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$mercredi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$mercredi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$mercredi->date()]->getSiteDepart();
					$id		 = $e[$mercredi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas"><?php echo $entrantRepas; ?></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- jeudi -->
				<?php if ($days['jeudi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$jeudi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$jeudi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$jeudi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$jeudi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$jeudi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$jeudi->date()]->getSiteDepart();
					$id		 = $e[$jeudi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- vendredi -->
				<?php if ($days['vendredi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$vendredi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$vendredi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$vendredi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$vendredi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$vendredi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$vendredi->date()]->getSiteDepart();
					$id		 = $e[$vendredi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- samedi -->
				<?php if ($days['samedi']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$samedi->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$samedi->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$samedi->date()]->sortie);
					$entrantRepas	 = ((int) $e[$samedi->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$samedi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$samedi->date()]->getSiteDepart();
					$id		 = $e[$samedi->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- dimanche -->
				<?php if ($days['dimanche']): ?>
				    <?php
				    $entrantCode	 = '';
				    $entrantEntree	 = '';
				    $entrantSortie	 = '';
				    $entrantRepas	 = '';
				    $entrantPause	 = '';
				    $class		 = '';
				    $depart		 = new Site();
				    $id		 = 0;
				    if (isset($e[$dimanche->date()]) && $en->arrivee == $siteId) {
					$entrantCode	 = 'TE';
					$entrantEntree	 = RHDateTime::hourNoSecond($e[$dimanche->date()]->entree);
					$entrantSortie	 = RHDateTime::hourNoSecond($e[$dimanche->date()]->sortie);
					$entrantRepas	 = ((int) $e[$dimanche->date()]->repas == 1) ? '1' : '';
					$entrantPause	 = ((int) $e[$dimanche->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$entrantCode'";
					$depart		 = $e[$dimanche->date()]->getSiteDepart();
					$id		 = $e[$dimanche->date()]->id;
				    }
				    ?>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-code">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantCode; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-entree">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantEntree; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-sortie">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantSortie; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-pause">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantPause; ?></a>
	    			</td>
	    			<td<?php echo $class; ?> id="t-<?php echo $id; ?>-repas">
	    			    <a href='#' class='edit-transfert' data-id="<?php echo $id; ?>"><?php echo $entrantRepas; ?></a>
	    			</td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert" title="Effacer le transfert" data-id="<?php echo $id; ?>"><?php echo $depart->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>
				<td colspan="3" class="stripes"></td>
			    </tr>
			<?php endforeach; ?>
		    <?php else: ?>
    		    <tr>
			    <?php for ($i = 0; $i < $colCount; $i++): ?>
				<td <?php echo ($i < 4) ? 'class="jaune1"' : ''; ?>>&nbsp;</td>
			    <?php endfor; ?>
    		    </tr>
		    <?php endif; ?>
		    <tr>
			<td colspan='<?php echo $colCount; ?>' class='jaune3'>Transfert Sortants</td>
		    </tr>
		    <?php
		    $sortants	 = $this->sortants;
		    $count		 = count($sortants);
		    $jaune		 = 1;
//			    echo "<pre>Sortants TOTAL</pre>";
//			    var_dump($sortants);
		    ?>
		    <?php if ($count > 0): ?>
			<?php $i = 1; ?>
			<?php foreach ($sortants as $e): ?>
			    <?php
			    $en	 = null;
			    $i	 = 1;
			    // Le Transfert
			    foreach ($e as $t) {
				$en = $t;
				//	    echo "<pre>Sortants $i</pre>";
//	    $i++;
//	    var_dump($en);
				break;
			    }
			    ?>
			    <?php
//				    echo "<pre>Avant Affichage</pre>";
//				    var_dump($en);
			    $empl		 = $en->getEmploye();
			    $poste		 = $empl->getPoste();
			    ?>
			    <tr>
				<?php
				$matricule	 = '&nbsp;';
				$posteCode	 = '&nbsp;';
				$prenom		 = '&nbsp;';
				$contrat	 = '&nbsp;';
				?>
				<?php
				if ($en->depart == $siteId) {
				    $matricule	 = $empl->matricule;
				    $posteCode	 = $poste->code;
				    $prenom		 = $empl->prenom;
				    $contrat	 = $empl->getHoraireHebdo(true);
				}
				else {
				    continue;
				}
				?>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>">
				    <a href="<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'edit', 'id' => $matricule)) ?>" target="_blank"><?php echo $matricule; ?></a>
				</td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>"><?php echo $posteCode; ?></td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>">
				    <a href="<?php echo $this->url('RHX/default', array('controller' => 'employe', 'action' => 'edit', 'id' => $matricule)) ?>" target="_blank"><?php echo $prenom; ?></a>
				</td>
				<td class="<?php echo ($jaune % 2) ? 'jaune1' : 'jaune2' ?>"><?php echo $contrat; ?></td>

				<!-- lundi -->
				<?php if ($days['lundi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$lundi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$lundi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$lundi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$lundi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$lundi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$lundi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $lundi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="lundi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $lundi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="lundi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $lundi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="lundi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $lundi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="lundi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $lundi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="lundi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- mardi -->
				<?php if ($days['mardi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$mardi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$mardi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$mardi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$mardi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$mardi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$mardi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mardi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mardi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mardi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mardi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mardi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mardi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mardi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mardi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mardi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mardi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- mercredi -->
				<?php if ($days['mercredi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$mercredi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$mercredi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$mercredi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$mercredi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$mercredi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$mercredi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mercredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-jour="<?php echo $mercredi->date(); ?>" data-prefix="mercredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mercredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mercredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mercredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mercredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mercredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mercredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $mercredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="mercredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- jeudi -->
				<?php if ($days['jeudi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$jeudi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$jeudi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$jeudi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$jeudi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$jeudi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$jeudi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $jeudi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="jeudi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $jeudi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="jeudi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $jeudi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="jeudi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $jeudi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="jeudi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $jeudi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="jeudi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- vendredi -->
				<?php if ($days['vendredi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$vendredi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$vendredi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$vendredi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$vendredi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$vendredi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$vendredi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $vendredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="vendredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $vendredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="vendredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $vendredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="vendredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $vendredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="vendredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $vendredi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="vendredi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- samedi -->
				<?php if ($days['samedi']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$samedi->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$samedi->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$samedi->date()]->sortie);
					$sortantRepas	 = ((int) $e[$samedi->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$samedi->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$samedi->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $samedi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="samedi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $samedi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="samedi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $samedi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="samedi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $samedi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="samedi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $samedi->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="samedi" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>

				<!-- dimanche -->
				<?php if ($days['dimanche']): ?>
				    <?php
				    $sortantCode	 = '';
				    $sortantEntree	 = '';
				    $sortantSortie	 = '';
				    $sortantRepas	 = '';
				    $sortantPause	 = '';
				    $class		 = '';
				    $arrivee	 = new Site();
				    $id		 = 0;
				    if (isset($e[$dimanche->date()]) && $en->depart == $siteId) {
					$sortantCode	 = 'TS';
					$sortantEntree	 = RHDateTime::hourNoSecond($e[$dimanche->date()]->entree);
					$sortantSortie	 = RHDateTime::hourNoSecond($e[$dimanche->date()]->sortie);
					$sortantRepas	 = ((int) $e[$dimanche->date()]->repas == 1) ? '1' : '';
					$sortantPause	 = ((int) $e[$dimanche->date()]->pause == 1) ? 'X' : '';
					$class		 = " class='$sortantCode'";
					$arrivee	 = $e[$dimanche->date()]->getSiteArrivee();
					$id		 = $en->id;
				    }
				    ?>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $dimanche->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="dimanche" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantCode; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $dimanche->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="dimanche" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantEntree; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $dimanche->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="dimanche" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantSortie; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $dimanche->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="dimanche" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantPause; ?></a></td>
	    			<td<?php echo $class; ?>><a href="#" class="applyTransfert" data-jour="<?php echo $dimanche->date(); ?>" data-matricule="<?php echo $matricule; ?>" data-prefix="dimanche" data-entree="<?php echo $sortantEntree; ?>" data-sortie="<?php echo $sortantSortie; ?>" data-pause="<?php echo $sortantPause; ?>" data-repas="<?php echo $sortantRepas; ?>"><?php echo $sortantRepas; ?></a></td>
	    			<td<?php echo $class; ?>>
	    			    <div style="position: relative">
	    				<a href="#" class="cancel-transfert_" title="" data-id="<?php echo $id; ?>"><?php echo $arrivee->libelle; ?></a>
	    				<a href="#" id="icon-<?php echo $id; ?>" class="icon-transfert_" data-id="<?php echo $id; ?>" style="display: none">
	    				    <img src="<?php echo $this->url('RHX/default'); ?>/../../img/rhx/close-12x12.png">
	    				</a>
	    			    </div>
	    			</td>
				<?php endif; ?>
				<td colspan="3" class="stripes"></td>
			    </tr>
			<?php endforeach; ?>
		    <?php else: ?>
    		    <tr>
			    <?php for ($i = 0; $i < $colCount; $i++): ?>
				<td <?php echo ($i < 4) ? 'class="jaune1"' : ''; ?>>&nbsp;</td>
			    <?php endfor; ?>
    		    </tr>
		    <?php endif; ?>
		    <tr>
			<td colspan="4" class="jaune2">Synthèse</td>

			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" class="jaune2" style="text-align: center">Jour</td>
				<td colspan="3" class="jaune2" style="text-align: center">Semaine</td>
			    <?php endif; ?>
			<?php endfor; ?>

			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- HEURES TOTALES -->
		    <tr>
			<td colspan="4" class="jaune2" style="/*text-align: center*/">Heures totales</td>
			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center;">
				    <span id="<?php echo $dayName[$i] . '-heures-totales' ?>">0,0</span>
				</td>
				<td colspan="3" style="text-align: center;"></td>
			    <?php endif; ?>
			<?php endfor; ?>
		    </tr>

		    <!-- HEURES TRAVAILLEES -->
		    <tr>
			<td colspan="4" class="jaune2" style="/*text-align: center*/">Heures travaillées</td>
			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center;">
				    <span id="<?php echo $dayName[$i] . '-heures-travaillees' ?>">0,0</span>
				</td>
				<td colspan="3" style="text-align: center;">

				</td>
			    <?php endif; ?>
			<?php endfor; ?>
		    </tr>

		    <!-- MO TOTALE -->
		    <tr>
			<td colspan="4" class="jaune2" style="/*text-align: center*/">MO Travaillées</td>
			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center;">
				    <span id="<?php echo $dayName[$i] . '-mo-totales' ?>">0,0 €</span>
				</td>
				<td colspan="3" style="text-align: center;"></td>
			    <?php endif; ?>
			<?php endfor; ?>
		    </tr>

		    <!-- Dont détail transfert MO Sortant -->
		    <tr>
			<td colspan="4" class="jaune2">MO Sortant</td>

			<!-- lundi -->
			<?php if ($days['lundi']): ?>
    			<td colspan="3" style="text-align: center" id='lundi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mardi -->
			<?php if ($days['mardi']): ?>
    			<td colspan="3" style="text-align: center" id='mardi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mercredi -->
			<?php if ($days['mercredi']): ?>
    			<td colspan="3" style="text-align: center" id='mercredi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- jeudi -->
			<?php if ($days['jeudi']): ?>
    			<td colspan="3" style="text-align: center" id='jeudi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- vendredi -->
			<?php if ($days['vendredi']): ?>
    			<td colspan="3" style="text-align: center" id='vendredi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- samedi -->
			<?php if ($days['samedi']): ?>
    			<td colspan="3" style="text-align: center" id='samedi-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- dimanche -->
			<?php if ($days['dimanche']): ?>
    			<td colspan="3" style="text-align: center" id='dimanche-sortant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>
			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- Détail transferts MO entrante -->
		    <tr>
			<td colspan="4" class="jaune2">MO entrante</td>

			<!-- lundi -->
			<?php if ($days['lundi']): ?>
    			<td colspan="3" style="text-align: center" id='lundi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mardi -->
			<?php if ($days['mardi']): ?>
    			<td colspan="3" style="text-align: center" id='mardi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mercredi -->
			<?php if ($days['mercredi']): ?>
    			<td colspan="3" style="text-align: center" id='mercredi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- jeudi -->
			<?php if ($days['jeudi']): ?>
    			<td colspan="3" style="text-align: center" id='jeudi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- vendredi -->
			<?php if ($days['vendredi']): ?>
    			<td colspan="3" style="text-align: center" id='vendredi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- samedi -->
			<?php if ($days['samedi']): ?>
    			<td colspan="3" style="text-align: center" id='samedi-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- dimanche -->
			<?php if ($days['dimanche']): ?>
    			<td colspan="3" style="text-align: center" id='dimanche-entrant'>0,00 €</td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>
			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- Nombre de personne à -->
		    <tr>
			<td colspan="4" class='jaune2'>Nombre de personnes <br>sur le site à <a href="#" id="heurePresence" data-type="combodate" data-template='HH:mm' data-format="HH:mm" data-viewformat="HH:mm">12:00</a></td>

			<!-- lundi -->
			<?php if ($days['lundi']): ?>
    			<td colspan="3" style="text-align: center"><span id="lundiPresent"><?php //echo $lundiPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mardi -->
			<?php if ($days['mardi']): ?>
    			<td colspan="3" style="text-align: center"><span id="mardiPresent"><?php //echo $mardiPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- mercredi -->
			<?php if ($days['mercredi']): ?>
    			<td colspan="3" style="text-align: center"><span id="mercrediPresent"><?php //echo $mercrediPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- jeudi -->
			<?php if ($days['jeudi']): ?>
    			<td colspan="3" style="text-align: center"><span id="jeudiPresent"><?php //echo $jeudiPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- vendredi -->
			<?php if ($days['vendredi']): ?>
    			<td colspan="3" style="text-align: center"><span id="vendrediPresent"><?php //echo $vendrediPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- samedi -->
			<?php if ($days['samedi']): ?>
    			<td colspan="3" style="text-align: center"><span id="samediPresent"><?php //echo $samediPresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>

			<!-- dimanche -->
			<?php if ($days['dimanche']): ?>
    			<td colspan="3" style="text-align: center"><span id="dimanchePresent"><?php //echo $dimanchePresent;  ?></span></td>
    			<td colspan="3" style="text-align: center"></td>
			<?php endif; ?>
			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- PRODUCTIVITE -->
		    <tr>
			<!-- Titre de colonne -->
			<td colspan="4" class="jaune2">Productivité</td>
			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center">
				    <span id="prod-<?php echo $dayName[$i]; ?>"><?php ?></span>
				</td>
				<td colspan="3" style="text-align: center"></td>
			    <?php endif; ?>
			<?php endfor; ?>
		    </tr>

		    <!-- Prévision de CA HT -->
		    <tr>
			<td colspan="4" class="jaune2">Prévision de CA HT</td>

			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center">
				    <span id="prev_ca-<?php echo $dayName[$i]; ?>"><?php ?> </span>&nbsp;€
				</td>
				<td colspan="3" style="text-align: center"></td>
			    <?php endif; ?>
			<?php endfor; ?>


			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- Ration MO -->
		    <tr>
			<td colspan="4" class="jaune2">Ratio MO</td>

			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center">
				    <span id='ratio-<?php echo $dayName[$i]; ?>'>0,00</span>&nbsp;%
				</td>
				<td colspan="3" style="text-align: center"></td>
			    <?php endif; ?>
			<?php endfor; ?>
		    </tr>

		    <!-- Nombre de personnes idéalement sur le Restaurant -->
		    <tr>
			<td colspan="4" class="jaune2">Nombre de personnes idéalement<br> sur le Restaurant</td>

			<?php foreach ($dayName as $day): ?>
			    <?php if ($days[$day]): ?>
				<td colspan="3" style="text-align: center">
				    <?php $ideal = $this->ideals[$day] ?>
				    <a href='#' class='edit-ideal' id='ideal-<?php echo $day; ?>' data-prefix='<?php echo $day; ?>' data-type='text' data-id='<?php echo $ideal->id ?>' data-date='<?php echo ($ideal->jour == '0000-00-00') ? $$day->date() : $ideal->jour ?>' data-site='<?php echo $siteId ?>'><?php echo $ideal->nb; ?></a>
				</td>
				<td colspan="3" style="text-align: center"></td>
			    <?php endif; ?>
			<?php endforeach; ?>

			<td colspan="3" class="stripes"></td>
		    </tr>

		    <!-- Ecarts -->
		    <tr>
			<td colspan="4" class="jaune2">Ecarts</td>

			<?php for ($i = 0; $i < 7; $i++): ?>
			    <?php if ($days[$dayName[$i]]): ?>
				<td colspan="3" style="text-align: center">
				    <span id="ecart-<?php echo $dayName[$i]; ?>"><?php ?> </span>
				</td>
				<td colspan="3" style="text-align: center"></td>
			    <?php endif; ?>
			<?php endfor; ?>

			<td colspan="3" class="stripes"></td>
		    </tr>
		</tbody>
	    </table>
	</div>
	<div id="planning-type">
	    <!-- AJAX CONTENT -->
	</div>
    </div>
</div>

<script type="text/javascript">
    // Tableau des ID plannings
    planningID = new Array();
<?php
$i	 = 0;
$plan	 = null;
?>
<?php foreach ($planningID as $plan): ?>
        planningID[<?php echo $i++; ?>] = <?php echo $plan->id; ?>;
<?php endforeach; ?>

    // Au chargement de la page
    $(function() { 		// Chargement du planning Type
	adresse = '<?php echo $this->url('RHX/default', array('controller' => 'template', 'action' => 'edit', 'id' => $tpl)) ?>';
	site = '<?php echo $this->site ?>';
	ajaxP = $.ajax({
	    type: 'post',
	    url: adresse,
	    data: "&site_id=" + site + "&nohead=1"});
	ajaxP.success(function(data) {
	    $('#planning-type').html(data);
	});
	ajaxP.error(function(xhr, options, thrownError) {
	    error = "";
	    if (xhr.status == 404) {
		error = "<em>Planning Type Introuvable! Le Planning Type n'a peut être pas été assigné!</em>";
	    } else if (xhr.status == 500) {
		error = "<em>Une erreur Serveur !</em>";
	    }
	    $('#planning-type').html(error);
	});

	// Tabulation
	$('#planning-tabs').tabs();
	// Position de la souris lors du clic
	$('.edit-link').click(function(event) {
	    event.preventDefault();
<?php if (!$editable): ?>
    	    return false;
<?php endif; ?>
	    // Récupération des variables
	    id = $(this).attr('data-id');
	    prefix = $(this).attr('data-prefix');
	    // Position de la souris
	    x = event.pageX;
	    y = event.pageY;
	    // Taille de l'écran
	    sw = $(window).width();
	    sh = $(window).height();
	    // Taille du dialogue
	    dw = 500;
	    dh = 400;
	    // Positionnement du dialogue
	    px = 0;
	    py = 0;
	    // Test sur la largeur
	    if ((sw - (dw + x)) > 0) {
		px = x;
	    } else {
		px = x - dw;
	    }
	    // Test sur la hauteur
	    //alert('Hauteur Fenetre : ' + sh + ', Y : ' + y + ', Hauteur Document : ' + dh);
	    if ((sh - y) >= dh - 250) {
		py = y - 40;
	    } else {
		py = y - dh + 80;
	    }
	    // Suppression des autres DIV conteneur
	    $('.rhPopover').remove();
	    // Ajout d'un div conteneur
	    $('#pl-' + id + '-' + prefix + '-code').append("<div class='rhPopover'></div>");
	    //alert('pl-' + id + '-code');
	    // Chargement du contenu
	    ajax = $.ajax({
		type: "post",
		url: "<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'popin')) ?>",
		data: "&id=" + id + "&prefix=" + prefix
	    });
	    ajax.success(function(data) {
		$('.rhPopover').hide().html(data).css({
		    'top': py,
		    'left': px
		}).show('normal');
	    });
	    ajax.error(function() {
		alert("Erreur de chargement");
	    });
	    // Détecter clic en dehors du DIV
	    $(document).mouseup(function(e) {
		var container = $(".rhPopover");
		if (container.has(e.target).length === 0) { 			    // Suppression du DIV
		    container.remove();
		}
	    });
	});
	$('.no-edit-link').click(function(event) {
	    event.preventDefault();
	    showError("Impossible d'éditer ce code activité!");
	});
	// Heure Présence
	$('#heurePresence').editable({
	    placement: 'right',
	    format: 'HH:mm',
	    combodate: {
		firstItem: 'name'
	    },
	    title: "Heure & Minute",
	    validate: function(value) {
		val = value.hour() + ':' + value.minute();
		presence(val);
	    }
	});

	// Chargement automatique de tout les données dynamiques
	// Parcours des Lignes
<?php $it = 0; ?>
<?php foreach ($planningID as $plan): ?>
    	console.log('Calcul semaine du planning #<?php echo $plan->id; ?>');
    	calculRow(<?php echo $plan->id; ?>);
    <?php $it++; ?>
<?php endforeach; ?>

	// Parcours des colonnes
	planning = <?php echo (isset($plan) || !is_null($plan)) ? $plan->id : 0; ?>;
	ajaxCol = $.ajax({
	    //dataType: "json",
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'fillCol')); ?>',
	    data: '&site=<?php echo $siteId; ?>&lundi=<?php echo $lundi->date(); ?>'
	});
	ajaxCol.success(function(result) {
	    // Récupération
	    heures = result.heures;
	    site = result.site;
	    entrant = result.entrant;
	    sortant = result.sortant;
	    // Assignation
	    $('#lundi-heure').hide().fadeIn('normal').text(heures.lundi);
	    $('#mardi-heure').hide().fadeIn('normal').text(heures.mardi);
	    $('#mercredi-heure').hide().fadeIn('normal').text(heures.mercredi);
	    $('#jeudi-heure').hide().fadeIn('normal').text(heures.jeudi);
	    $('#vendredi-heure').hide().fadeIn('normal').text(heures.vendredi);
	    $('#samedi-heure').hide().fadeIn('normal').text(heures.samedi);
	    $('#dimanche-heure').hide().fadeIn('normal').text(heures.dimanche);

	    $('#lundi-mo').hide().fadeIn('normal').text(site.lundi + ' €');
	    $('#mardi-mo').hide().fadeIn('normal').text(site.mardi + ' €');
	    $('#mercredi-mo').hide().fadeIn('normal').text(site.mercredi + ' €');
	    $('#jeudi-mo').hide().fadeIn('normal').text(site.jeudi + ' €');
	    $('#vendredi-mo').hide().fadeIn('normal').text(site.vendredi + ' €');
	    $('#samedi-mo').hide().fadeIn('normal').text(site.samedi + ' €');
	    $('#dimanche-mo').hide().fadeIn('normal').text(site.dimanche + ' €');

	    $('#lundi-entrant').hide().fadeIn('normal').text(entrant.lundi + ' €');
	    $('#mardi-entrant').hide().fadeIn('normal').text(entrant.mardi + ' €');
	    $('#mercredi-entrant').hide().fadeIn('normal').text(entrant.mercredi + ' €');
	    $('#jeudi-entrant').hide().fadeIn('normal').text(entrant.jeudi + ' €');
	    $('#vendredi-entrant').hide().fadeIn('normal').text(entrant.vendredi + ' €');
	    $('#samedi-entrant').hide().fadeIn('normal').text(entrant.samedi + ' €');
	    $('#dimanche-entrant').hide().fadeIn('normal').text(entrant.dimanche + ' €');

	    $('#lundi-sortant').hide().fadeIn('normal').text(sortant.lundi + ' €');
	    $('#mardi-sortant').hide().fadeIn('normal').text(sortant.mardi + ' €');
	    $('#mercredi-sortant').hide().fadeIn('normal').text(sortant.mercredi + ' €');
	    $('#jeudi-sortant').hide().fadeIn('normal').text(sortant.jeudi + ' €');
	    $('#vendredi-sortant').hide().fadeIn('normal').text(sortant.vendredi + ' €');
	    $('#samedi-sortant').hide().fadeIn('normal').text(sortant.samedi + ' €');
	    $('#dimanche-sortant').hide().fadeIn('normal').text(sortant.dimanche + ' €');

	    productivite = result.productivite;
	    $('#prod-lundi').hide().fadeIn('normal').text(productivite.lundi);
	    $('#prod-mardi').hide().fadeIn('normal').text(productivite.mardi);
	    $('#prod-mercredi').hide().fadeIn('normal').text(productivite.mercredi);
	    $('#prod-jeudi').hide().fadeIn('normal').text(productivite.jeudi);
	    $('#prod-vendredi').hide().fadeIn('normal').text(productivite.vendredi);
	    $('#prod-samedi').hide().fadeIn('normal').text(productivite.samedi);
	    $('#prod-dimanche').hide().fadeIn('normal').text(productivite.dimanche);

	    prevision_ca = result.prevision_ca;
	    $('#prev_ca-lundi').hide().fadeIn('normal').text(prevision_ca.lundi);
	    $('#prev_ca-mardi').hide().fadeIn('normal').text(prevision_ca.mardi);
	    $('#prev_ca-mercredi').hide().fadeIn('normal').text(prevision_ca.mercredi);
	    $('#prev_ca-jeudi').hide().fadeIn('normal').text(prevision_ca.jeudi);
	    $('#prev_ca-vendredi').hide().fadeIn('normal').text(prevision_ca.vendredi);
	    $('#prev_ca-samedi').hide().fadeIn('normal').text(prevision_ca.samedi);
	    $('#prev_ca-dimanche').hide().fadeIn('normal').text(prevision_ca.dimanche);

	    // Heures total
	    total = result.total;
	    $('#lundi-heures-totales').hide().fadeIn('normal').text(total.lundi);
	    $('#mardi-heures-totales').hide().fadeIn('normal').text(total.mardi);
	    $('#mercredi-heures-totales').hide().fadeIn('normal').text(total.mercredi);
	    $('#jeudi-heures-totales').hide().fadeIn('normal').text(total.jeudi);
	    $('#vendredi-heures-totales').hide().fadeIn('normal').text(total.vendredi);
	    $('#samedi-heures-totales').hide().fadeIn('normal').text(total.samedi);
	    $('#dimanche-heures-totales').hide().fadeIn('normal').text(total.dimanche);

	    // Heures travaillees
	    travaille = result.travaille;
	    $('#lundi-heures-travaillees').hide().fadeIn('normal').text(travaille.lundi);
	    $('#mardi-heures-travaillees').hide().fadeIn('normal').text(travaille.mardi);
	    $('#mercredi-heures-travaillees').hide().fadeIn('normal').text(travaille.mercredi);
	    $('#jeudi-heures-travaillees').hide().fadeIn('normal').text(travaille.jeudi);
	    $('#vendredi-heures-travaillees').hide().fadeIn('normal').text(travaille.vendredi);
	    $('#samedi-heures-travaillees').hide().fadeIn('normal').text(travaille.samedi);
	    $('#dimanche-heures-travaillees').hide().fadeIn('normal').text(travaille.dimanche);

	    // MO Total
	    mo = result.mo;
	    $('#lundi-mo-totales').hide().fadeIn('normal').text(mo.lundi);
	    $('#mardi-mo-totales').hide().fadeIn('normal').text(mo.mardi);
	    $('#mercredi-mo-totales').hide().fadeIn('normal').text(mo.mercredi);
	    $('#jeudi-mo-totales').hide().fadeIn('normal').text(mo.jeudi);
	    $('#vendredi-mo-totales').hide().fadeIn('normal').text(mo.vendredi);
	    $('#samedi-mo-totales').hide().fadeIn('normal').text(mo.samedi);
	    $('#dimanche-mo-totales').hide().fadeIn('normal').text(mo.dimanche);

	    // Ratio MO
	    //alert ('Calcul RATIO MO');
	    $lundi = calculRatioMO(mo.lundi, sortant.lundi, prevision_ca.lundi);
	    //alert('(' + mo.lundi + ' - ' + sortant.lundi + ')' + ' / ' + prevision_ca.lundi + ')');
	    $mardi = calculRatioMO(mo.mardi, sortant.mardi, prevision_ca.mardi);
	    $mercredi = calculRatioMO(mo.mercredi, sortant.mercredi, prevision_ca.mercredi);
	    $jeudi = calculRatioMO(mo.jeudi, sortant.jeudi, prevision_ca.jeudi);
	    $vendredi = calculRatioMO(mo.vendredi, sortant.vendredi, prevision_ca.vendredi);
	    $samedi = calculRatioMO(mo.samedi, sortant.samedi, prevision_ca.samedi);
	    $dimanche = calculRatioMO(mo.dimanche, sortant.dimanche, prevision_ca.dimanche);
	    $('#ratio-lundi').text(isNaN($lundi) ? '0,00' : showNumber($lundi));
	    $('#ratio-mardi').text(isNaN($mardi) ? '0,00' : showNumber($mardi));
	    $('#ratio-mercredi').text(isNaN($mercredi) ? '0,00' : showNumber($mercredi));
	    $('#ratio-jeudi').text(isNaN($jeudi) ? '0,00' : showNumber($jeudi));
	    $('#ratio-vendredi').text(isNaN($vendredi) ? '0,00' : showNumber($vendredi));
	    $('#ratio-samedi').text(isNaN($samedi) ? '0,00' : showNumber($samedi));
	    $('#ratio-dimanche').text(isNaN($dimanche) ? '0,00' : showNumber($dimanche));

	});
	ajaxCol.error(function(jqXHR, textStatus, errorThrown) {
	    console.log('XHR : ' + jqXHR);
	    console.log('StatusCode : ' + jqXHR.status);
	    console.log('ResponseText : ' + jqXHR.responseText);
	    console.log('responseType : ' + jqXHR.responseType);
	    console.log('Status : ' + textStatus);
	    console.log('Thrown : ' + errorThrown);
	});

	// Présence
	presence($('#heurePresence').text());

	// Effectuer un Transfert
	$('.makeTransfert').click(function(e) {
	    e.preventDefault();
	    site = $(this).attr('data-site');
	    ajax = $.ajax({
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'transfert', 'action' => 'planningTransfert')) ?>',
		data: '&site=' + site + '&lundi=<?php echo $lundi->date(); ?>&dimanche=<?php echo $dimanche->date(); ?>'
	    });
	    ajax.done(function(data) {
		$('#dialog1').html(data).dialog({
		    title: 'Effectuer un Transfert Entrant pour le site <?php echo $siteObj->libelle; ?>',
		    width: 1024,
		    height: 540,
		    modal: true,
		    autoOpen: true
		});
	    });
	});

	// Appliquer un transfert
	$('.applyTransfert').attr('title', 'Appliquer le Transfert au Planning Semaine');
	$('.applyTransfert').click(function(e) {
	    e.preventDefault();
	    code = <?php echo XRules::TransfertSortant; ?>;
	    prefix = $(this).attr('data-prefix');
	    entree = $(this).attr('data-entree');
	    sortie = $(this).attr('data-sortie');
	    pause = $(this).attr('data-pause');
	    repas = $(this).attr('data-repas');
	    matricule = $(this).attr('data-matricule');
	    jour = $(this).attr('data-jour');
	    // Traitement des données de Pause
	    pause = (pause === 'X') ? 1 : 0;
	    repas = (repas === '1') ? 1 : 0;
	    ajaxP = $.ajax({
		dataType: 'json',
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'getPlanningId')) ?>',
		data: '&matricule=' + matricule + '&date=' + jour
	    });
	    ajaxP.done(function(data) {
		// Sauvegarde des données à la façon du savePlanning
		ajaxSave = $.ajax({
		    dataType: 'json',
		    type: 'post',
		    url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'savePlanning')) ?>',
		    data: '&id=' + data.id + '&entree=' + entree + '&sortie=' + sortie + '&pause=' + pause + '&repas=' + repas + '&prefix=' + prefix + '&code=' + code
		});
		ajaxSave.done(function(dataSave) {
		    // Actualisation de la page
		    $('#' + ID).click();
		});
	    });
	});

	// Position relative
	$('.cancel-transfert').parent().addClass('relative-position');

	// Annuler Transfert
	$('.cancel-transfert').hover(function() {
	    id = $(this).attr('data-id');
	    //$('.icon-transfert').hide();
	    $('#icon-' + id).show('fast');
	}, function(e) {
//		    id = $(this).attr('data-id');
//		    $('#icon-' + id).hide('normal');
//		    $('.icon-transfert').hide('normal');
	});
	$('.icon-transfert').hover(function() {
	}, function() {
	    $('.icon-transfert').hide('normal');
	});


	// Annuler Transfert
	$('.cancel-transfert, .icon-transfert').click(function(e) {
	    e.preventDefault();
	    conf = confirm('Voulez-vous effacer ce transfert ?');
	    if (!conf) {
		return false;
	    }
	    id = $(this).attr("data-id");
	    ajax = $.ajax({
		dataType: 'json',
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'transfert', 'action' => 'cancel')); ?>',
		data: '&id=' + id
	    });
	    ajax.done(function(data) {
		// Rafraichissement de la page
		$('.rhx-siteTitle').click();
	    });
	    ajax.fail(function() {
		alert('Erreur !');
	    });
	});

	$('.edit-transfert').click(function(event) {
	    event.preventDefault();
<?php if (!$editable): ?>
    	    return false;
<?php endif; ?>
	    // Récupération des variables
	    id = $(this).attr('data-id');
	    // Position de la souris
	    x = event.pageX;
	    y = event.pageY;
	    // Taille de l'écran
	    sw = $(window).width();
	    sh = $(window).height();
	    // Taille du dialogue
	    dw = 300;
	    dh = 400;
	    // Positionnement du dialogue
	    px = 0;
	    py = 0;
	    // Test sur la largeur
	    if ((sw - (dw + x)) > 0) {
		px = x;
	    } else {
		px = x - dw;
	    }
	    // Test sur la hauteur
	    //alert('Hauteur Fenetre : ' + sh + ', Y : ' + y + ', Hauteur Document : ' + dh);
	    if ((sh - y) >= dh - 250) {
		py = y - 40;
	    } else {
		py = y - dh + 80;
	    }
	    // Suppression des autres DIV conteneur
	    $('.rhPopover').remove();
	    // Ajout d'un div conteneur
	    $('#t-' + id + '-code').append("<div class='rhPopover'></div>");
	    //alert('pl-' + id + '-code');
	    // Chargement du contenu
	    ajax = $.ajax({
		type: "post",
		url: "<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'popinTransfert')) ?>",
		data: "&id=" + id
	    });
	    ajax.success(function(data) {
		$('.rhPopover').hide().html(data).css({
		    'top': py,
		    'left': px
		}).show('normal');
	    });
	    ajax.error(function() {
		alert("Erreur de chargement");
	    });
	    // Détecter clic en dehors du DIV
	    $(document).mouseup(function(e) {
		var container = $(".rhPopover");
		if (container.has(e.target).length === 0) { 			    // Suppression du DIV
		    container.remove();
		}
	    });
	});
	// Afficher le résumé
	$('.show-resume').click(function(e) {
	    e.preventDefault();
	    id = $(this).attr('data-id');
	    matricule = $(this).attr('data-matricule');
	    lundi = $(this).attr('data-lundi');
	    ajax = $.ajax({
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'showResume')) ?>',
		data: '&id=' + id + '&matricule=' + matricule + '&lundi=' + lundi
	    });
	    ajax.done(function(result) {
		showInfo(result);
	    });
	});

	// Sélection des autres semaines
<?php
$semaines	 = $this->semaines;
$week		 = array();
foreach ($semaines as $semaine) {
    $lundiS			 = new RHDateTime($semaine->lundi);
    $dimanche		 = new RHDateTime($semaine->dimanche);
    $week[$semaine->id]	 = "$semaine->libelle : {$lundiS->dateFr()} au {$dimanche->dateFr()}";
}
?>
	$('#selectorSemaine').editable({
	    title: 'Liste des Semaines de la périodes',
	    inputclass: 'input-xlarge',
	    source: '<?php echo json_encode($week); ?>',
	    validate: function(value) {
		$('#s' + value).click();
	    }
	});

	// Nombre de personne ideal
	$('.edit-ideal').editable({
	    title: 'Nombre de personne idéal',
	    validate: function(value) {
		id = parseInt($(this).attr('data-id'));
		val = isNaN(parseInt(value)) ? 0 : parseInt(value);
		day = $(this).data('prefix');
		if (id > 0) {
		    // update
		    $ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'updateIdeal')) ?>',
			data: '&id=' + id + '&nb=' + val
		    });
		} else {
		    // insert
		    date = $(this).attr('data-date');
		    site = $(this).attr('data-site');
		    prefix = $(this).attr('data-prefix');
		    $ajax = $.ajax({
			type: 'post',
			url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'insertIdeal')) ?>',
			data: '&date=' + date + '&site=' + site + '&nb=' + val
		    });
		    $ajax.done(function(result) {
			$("#ideal-" + prefix).attr('data-id', result.ideal.id);
		    });
		}

	    },
	    success: function(value) {
		day = $(this).data('prefix');

		setTimeout(function() {
		    calculEcart(day);
		}, 100);

	    }
	});
    });


    function presence(value) {
	val = value;

	ajax = $.ajax({
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'calculator', 'action' => 'comptePersonne')) ?>',
	    data: '&site=<?php echo $siteId; ?>&lundi=<?php echo $lundi->date(); ?>&value=' + val
	});
	ajax.done(function(result) {
	    $('#lundiPresent').hide().fadeIn('normal').text(result.lundi);
	    $('#mardiPresent').hide().fadeIn('normal').text(result.mardi);
	    $('#mercrediPresent').hide().fadeIn('normal').text(result.mercredi);
	    $('#jeudiPresent').hide().fadeIn('normal').text(result.jeudi);
	    $('#vendrediPresent').hide().fadeIn('normal').text(result.vendredi);
	    $('#samediPresent').hide().fadeIn('normal').text(result.samedi);
	    $('#dimanchePresent').hide().fadeIn('normal').text(result.dimanche);

	    calculEcart();
	});
	ajax.fail(function(jqXHR, textStatus, errorThrown) {
	    //alert(jqXHR.status);
	    $('#lundiPresent').hide().fadeIn('normal').text("0");
	    $('#mardiPresent').hide().fadeIn('normal').text("0");
	    $('#mercrediPresent').hide().fadeIn('normal').text("0");
	    $('#jeudiPresent').hide().fadeIn('normal').text("0");
	    $('#vendrediPresent').hide().fadeIn('normal').text("0");
	    $('#samediPresent').hide().fadeIn('normal').text("0");
	    $('#dimanchePresent').hide().fadeIn('normal').text("0");
	});
    }

    function calculEcart(day) {
	if (!day)
	    day = 'all';
	var dayWeek = ['lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'],
		update_one = function(day) {
		    nb_pers = $.trim($('#' + day + 'Present').text());
		    nb_ideal = $.trim($('#ideal-' + day).text());

		    nb_pers = parseInt(nb_pers);
		    nb_ideal = parseInt(nb_ideal);

		    kaj = nb_pers - nb_ideal;
		    $('#ecart-' + day).hide().fadeIn('normal').text(kaj > 0 ? '+' + kaj : kaj);
		};

	if (day === 'all') {
	    $(dayWeek).each(function(k, v) {
		update_one(v);
	    });
	}
	else {
	    update_one(day);
	}
    }

// Calcul des Cumul Ligne
    function calculRow(planningId) {
	ajax = $.ajax({
	    dataType: 'json',
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'calculRow')) ?>',
	    data: '&json=on&id=' + planningId
	});
	ajax.done(function(result) {
	    total = result.total;
	    selector = '#pl-' + planningId;
	    $(selector + '-retard').hide().html(total.heurePRDA + '(' + total.nbPRDA + ')').fadeIn('normal');
	    val = result.heureNonPlannifie;
	    if (val.substr(0, 1) === '-') {
		$(selector + '-planifie').removeClass().addClass('minusValue');
	    } else {
		$(selector + '-planifie').removeClass().addClass('plusValue');
	    }
	    $(selector + '-planifie').hide().html(val).fadeIn('normal');
	});
	ajax.fail(function() {
	    selector = '#pl-' + planningId;
	    $(selector + '-retard').hide().html('#').fadeIn('normal');
	    $(selector + '-planifie').hide().html('#').fadeIn('normal');
	});
    }

    function calculSemaine(plId) {
	ajax = $.ajax({
	    dataType: 'json',
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'calculator', 'action' => 'calculSemaine')) ?>',
	    data: '&id=' + plId
	});
	ajax.done(function(result) {
	    data = result.data;
	    $(selector + '-retard').hide().html(data.totalHeurePRDA + '(' + data.totalPRDA + ')').fadeIn('normal');
	    // calcul des heures non planifié
	    ajaxHNP = $.ajax({
		dataType: 'json',
		type: 'post',
		url: '<?php echo $this->url('RHX/default', array('controller' => 'calculator', 'action' => 'calculPeriode')) ?>',
		data: '&id=' + data.periodeId + '&matricule=' + data.matricule
	    });
	    ajaxHNP.done(function(jsonData) {
		selector = '#pl-' + plId;
		val = jsonData.heureNonPlanifie + '';
		console.log(selector);
		if (val.substr(0, 1) === '-') {
		    $(selector + '-planifie').removeClass().addClass('minusValue');
		} else {
		    $(selector + '-planifie').removeClass().addClass('plusValue');
		}
		$(selector + '-planifie').hide().html(val).fadeIn('normal');
	    });
	    ajaxHNP.fail(function() {
	    });
	});
    }

    function calculateCol(planning, site, date) {
	// Parcours des colonnes
	// planning = <?php echo (isset($plan) || !is_null($plan)) ? $plan->id : 0; ?>;
	ajaxCol = $.ajax({
	    dataType: "json",
	    type: 'post',
	    url: '<?php echo $this->url('RHX/default', array('controller' => 'planning', 'action' => 'fillCol')); ?>',
	    data: '&site=' + site + '&lundi=' + date
	});
	ajaxCol.success(function(result) {
	    // Récupération
	    heures = result.heures;
	    site = result.site;
	    entrant = result.entrant;
	    sortant = result.sortant;
	    productivite = result.productivite;
	    prevision_ca = result.prevision_ca;//alert(prevision_ca);
	    // Assignation
	    // Heure travaillées sur site
	    $('#lundi-heure').hide().fadeIn('normal').text(heures.lundi);
	    $('#mardi-heure').hide().fadeIn('normal').text(heures.mardi);
	    $('#mercredi-heure').hide().fadeIn('normal').text(heures.mercredi);
	    $('#jeudi-heure').hide().fadeIn('normal').text(heures.jeudi);
	    $('#vendredi-heure').hide().fadeIn('normal').text(heures.vendredi);
	    $('#samedi-heure').hide().fadeIn('normal').text(heures.samedi);
	    $('#dimanche-heure').hide().fadeIn('normal').text(heures.dimanche);

	    // Main d'oeuvre
	    $('#lundi-mo').hide().fadeIn('normal').text(site.lundi + ' €');
	    $('#mardi-mo').hide().fadeIn('normal').text(site.mardi + ' €');
	    $('#mercredi-mo').hide().fadeIn('normal').text(site.mercredi + ' €');
	    $('#jeudi-mo').hide().fadeIn('normal').text(site.jeudi + ' €');
	    $('#vendredi-mo').hide().fadeIn('normal').text(site.vendredi + ' €');
	    $('#samedi-mo').hide().fadeIn('normal').text(site.samedi + ' €');
	    $('#dimanche-mo').hide().fadeIn('normal').text(site.dimanche + ' €');

	    // Transfert Entrants
	    $('#lundi-entrant').hide().fadeIn('normal').text(entrant.lundi + ' €');
	    $('#mardi-entrant').hide().fadeIn('normal').text(entrant.mardi + ' €');
	    $('#mercredi-entrant').hide().fadeIn('normal').text(entrant.mercredi + ' €');
	    $('#jeudi-entrant').hide().fadeIn('normal').text(entrant.jeudi + ' €');
	    $('#vendredi-entrant').hide().fadeIn('normal').text(entrant.vendredi + ' €');
	    $('#samedi-entrant').hide().fadeIn('normal').text(entrant.samedi + ' €');
	    $('#dimanche-entrant').hide().fadeIn('normal').text(entrant.dimanche + ' €');

	    // Transfert Sortant
	    $('#lundi-sortant').hide().fadeIn('normal').text(sortant.lundi + ' €');
	    $('#mardi-sortant').hide().fadeIn('normal').text(sortant.mardi + ' €');
	    $('#mercredi-sortant').hide().fadeIn('normal').text(sortant.mercredi + ' €');
	    $('#jeudi-sortant').hide().fadeIn('normal').text(sortant.jeudi + ' €');
	    $('#vendredi-sortant').hide().fadeIn('normal').text(sortant.vendredi + ' €');
	    $('#samedi-sortant').hide().fadeIn('normal').text(sortant.samedi + ' €');
	    $('#dimanche-sortant').hide().fadeIn('normal').text(sortant.dimanche + ' €');

	    // Productivité
	    $('#prod-lundi').hide().fadeIn('normal').text(productivite.lundi);
	    $('#prod-mardi').hide().fadeIn('normal').text(productivite.mardi);
	    $('#prod-mercredi').hide().fadeIn('normal').text(productivite.mercredi);
	    $('#prod-jeudi').hide().fadeIn('normal').text(productivite.jeudi);
	    $('#prod-vendredi').hide().fadeIn('normal').text(productivite.vendredi);
	    $('#prod-samedi').hide().fadeIn('normal').text(productivite.samedi);
	    $('#prod-dimanche').hide().fadeIn('normal').text(productivite.dimanche);


	    //Prevision CA  


	    // Heures total
	    total = result.total;
	    //alert(total.lundi);
	    $('#lundi-heures-totales').hide().fadeIn('normal').text(total.lundi);
	    $('#mardi-heures-totales').hide().fadeIn('normal').text(total.mardi);
	    $('#mercredi-heures-totales').hide().fadeIn('normal').text(total.mercredi);
	    $('#jeudi-heures-totales').hide().fadeIn('normal').text(total.jeudi);
	    $('#vendredi-heures-totales').hide().fadeIn('normal').text(total.vendredi);
	    $('#samedi-heures-totales').hide().fadeIn('normal').text(total.samedi);
	    $('#dimanche-heures-totales').hide().fadeIn('normal').text(total.dimanche);

	    // Heures travaillees
	    travaille = result.travaille;
	    $('#lundi-heures-travaillees').hide().fadeIn('normal').text(travaille.lundi);
	    $('#mardi-heures-travaillees').hide().fadeIn('normal').text(travaille.mardi);
	    $('#mercredi-heures-travaillees').hide().fadeIn('normal').text(travaille.mercredi);
	    $('#jeudi-heures-travaillees').hide().fadeIn('normal').text(travaille.jeudi);
	    $('#vendredi-heures-travaillees').hide().fadeIn('normal').text(travaille.vendredi);
	    $('#samedi-heures-travaillees').hide().fadeIn('normal').text(travaille.samedi);
	    $('#dimanche-heures-travaillees').hide().fadeIn('normal').text(travaille.dimanche);

	    // MO Total
	    mo = result.mo;
	    $('#lundi-mo-totales').hide().fadeIn('normal').text(mo.lundi + '€');
	    $('#mardi-mo-totales').hide().fadeIn('normal').text(mo.mardi + '€');
	    $('#mercredi-mo-totales').hide().fadeIn('normal').text(mo.mercredi + '€');
	    $('#jeudi-mo-totales').hide().fadeIn('normal').text(mo.jeudi + '€');
	    $('#vendredi-mo-totales').hide().fadeIn('normal').text(mo.vendredi + '€');
	    $('#samedi-mo-totales').hide().fadeIn('normal').text(mo.samedi + '€');
	    $('#dimanche-mo-totales').hide().fadeIn('normal').text(mo.dimanche + '€');

	    // Ratio MO
	    //alert('Calcul RATIO MO');
	    $lundi = (mo.lundi - sortant.lundi) / prevision_ca;
	    $mardi = (mo.mardi - sortant.mardi) / prevision_ca;
	    $mercredi = (mo.mercredi - sortant.mercredi) / prevision_ca;
	    $jeudi = (mo.jeudi - sortant.jeudi) / prevision_ca;
	    $vendredi = (mo.vendredi - sortant.vendredi) / prevision_ca;
	    $samedi = (mo.samedi - sortant.samedi) / prevision_ca;
	    $dimanche = (mo.dimanche - sortant.dimanche) / prevision_ca;
	    $('#ratio-lundi').text($lundi);
	    $('#ratio-mardi').text($mardi);
	    $('#ratio-mercredi').text($mercredi);
	    $('#ratio-jeudi').text($jeudi);
	    $('#ratio-vendredi').text($vendredi);
	    $('#ratio-samedi').text($samedi);
	    $('#ratio-dimanche').text($dimanche);

	});
	ajaxCol.error(function() {
	    //
	});

	// Présence
	val = $('#heurePresence').text();
	presence(val);
    }

    function calculRatioMO(mo, sortant, prevision) {
	mo = parseNumber(mo);
	sortant = parseNumber(sortant);
	prevision = parseNumber(prevision);
	//alert('(' + mo + ' - ' + sortant + ')' + ' / ' + prevision);
	return (prevision == 0) ? 0.0 : (mo - sortant) / prevision;
    }
    
    function parseNumber(str){
	//alert("Nombre a convertir : " + str);
	s = replaceVirgule(str);
	$return = isNaN(s) ? 0.0 : parseFloat(s);
	//alert("Nombre a convertir : " + s + "\nNombre converti : " + $return);
	return $return;
    }
    
    function showNumber(number){
	if(isNaN(number)) return '0,00';
	if(number == 0) return '0,00';
	var Num = number;
	number = Num.toFixed(2);
	strNumber = '' + number;
	if(strNumber.search('.') < 0) strNumber += '.00';
	return strNumber.replace('.', ',');
    }
    
    function replaceVirgule(str){
	str = '' + str;
	ret = str.replace(',', '.').replace(' ', '');
	//alert('Remplacement virgule par point : ' + str + ' => ' + ret);
	return ret;
    }
</script>
<style type="text/css">
    .rhx-goback{
	position: absolute;
	top: 55px;
	right: 100px;
	z-index: 99;
    }
    .rhx-siteTitle{
	position: absolute;
	top: 55px;
	left: 512px;
	z-index: 99;
	margin: auto;
	padding: 5px 15px;
	background: #7c98b3;
	border-radius: 3px;
	border: solid 1px #faf9f9;
	color: #faf9f9;
	font-size: 1.5em;
	opacity: 0.5;
    }
    .rhx-siteTitle:hover{
	opacity: 1.0;
    }
    .rhx-planning-title{
	position: absolute;
	top: 11px;
	right: 180px;
	color: white;
	font-size: 1.4em;
    }
    .rhPopover{
	position: absolute;
	z-index: 99;
	width: 500px;
    }
    .minusValue, .plusValue{
	display: inline-block;
	width: 100%;
	height: 100%;
	text-align: center;
	color: #ffffff;
    }
    .minusValue{
	background: #ff6633;
    }
    .plusValue{
	background: #008e37;
    }
<?php if (!$editable): ?>
        .edit-link{
    	cursor: not-allowed;
        }
<?php endif; ?>
    #heurePresence{
	font-weight: bolder;
	color: #6600ff;
    }
    .makeTransfert{
	position: relative;
	margin-left: 10px;
	display: inline-block;
	width: 32px;
	height: 32px;
	background: #fff;
	border-radius: 3px;
	box-shadow: 0px 0px 2px 3px #ffb400;
    }
    .icon-transfert{
	position: absolute;
	top: 1px;
	right: 1px;
    }
    .relative-position{
	position: relative;
    }
    .pl-table tbody tr:hover > td{
	/*	border-top-color: #010100 !important;
		border-bottom-color: #010100;*/
    }
</style>
